home *** CD-ROM | disk | FTP | other *** search
- /** 3DGPL *************************************************\
- * (Macintosh, 8bit deep bitmaps, 32bit machine) *
- * Header for hardware specific stuff. *
- * *
- * hardware.c hardware specific stuff. *
- * *
- * (6/1995) By Sergei Savhenko. (savs@cs.mcgill.ca). *
- * Copyright (c) 1995 Sergei Savchenko. *
- * THIS SOURCE CODE CAN'T BE USED FOR COMERCIAL PURPOSES *
- * WITHOUT AUTHORISATION *
- \**********************************************************/
- // Mac version hacked by Ingemar 1997
-
- #include "hardware.h" /* memset etc. */
-
- #include <QDOffScreen.h>
- #include <Palettes.h>
-
- static WindowPtr wind;
- static GWorldPtr offscreenGWorld;
-
- /**********************************************************\
- * Implementations for fast memory operations. *
- \**********************************************************/
-
- void HW_set_int(int *d,long l,int v) {long i; for(i=0;i<l;i++) *d++=v; }
-
- //void HW_set_int(int *dst,long lng,int val)
- //{
- //}
-
- #define rLeft 40
- #define rTop 40
-
-
- int HW_open_screen(char *display_name,
- char *screen_name,
- struct HW_colour palette[256],
- unsigned char *colourmap
- )
- {
- Rect boundsRect;
- OSErr myErr;
- CTabHandle theCTab;
- int i;
-
- InitGraf (&qd.thePort);
- InitFonts ();
- InitWindows ();
- InitMenus ();
- TEInit ();
- InitDialogs (nil);
- InitCursor ();
-
- SetRect(&boundsRect,rLeft,rTop,rLeft+HW_SCREEN_X_SIZE,rTop+HW_SCREEN_Y_SIZE);
- wind = NewCWindow(nil,&boundsRect,"\p",true,plainDBox,(WindowPtr)-1,false,0);
- SetPort(wind);
-
- // Set the palette to the one passed from 3DGPL
- theCTab = (CTabHandle)NewHandle(8 + 256 * 8); //8 bytes header + 8 bytes per colour}
- (**theCTab).ctSize = 255;
- (**theCTab).ctFlags = 0;
- for(i=0;i<256;i++)
- {
- (**theCTab).ctTable[i].value = i;
- (**theCTab).ctTable[i].rgb.red = palette[i].hw_r << 8;
- (**theCTab).ctTable[i].rgb.green = palette[i].hw_g << 8;
- (**theCTab).ctTable[i].rgb.blue = palette[i].hw_b << 8;
- }
- (**theCTab).ctSeed = GetCTSeed();
- SetEntries(0, 255, (**theCTab).ctTable);
- DisposeHandle((Handle)theCTab);
-
- // Create offscreen GWorld
- OffsetRect(&boundsRect, -boundsRect.left, -boundsRect.top);
- myErr = NewGWorld(&offscreenGWorld,8,&boundsRect,nil,nil,0);
- LockPixels(offscreenGWorld->portPixMap);
-
- // Use the base address passed from 3DGPL.
- // BUG: Doesn't dispose the old data
- (**offscreenGWorld->portPixMap).baseAddr = (char *)colourmap;
- (**offscreenGWorld->portPixMap).rowBytes = 0x8000 | HW_SCREEN_X_SIZE;
- }
-
- void HW_blit(void)
- {
- CGrafPtr savePort;
- GDHandle saveDev;
-
- CopyBits( &((GrafPtr)(offscreenGWorld))->portBits,
- &((GrafPtr)(wind))->portBits,
- &offscreenGWorld->portRect,
- &wind->portRect,
- srcCopy,nil);
- GetGWorld(&savePort, &saveDev);
- SetGWorld(offscreenGWorld, nil);
- PaintRect(&offscreenGWorld->portRect);
- SetGWorld(savePort, saveDev);
- }
-
- void HW_close_screen(void)
- {
- // Put back the palette
- RestoreDeviceClut(nil);
- DisposeWindow(wind);
- }
-
- static Boolean done;
-
- void HW_run_event_loop(void (*application_main)(void),
- void (*application_key_handler)(int key_code)
- )
- {
- EventRecord theEvent;
-
- done = false;
-
- while(!Button() && !done) // Temporary solution - set "done" with cmd-Q and/or click in close box instead
- {
- if(GetOSEvent(keyDownMask+autoKeyMask,&theEvent))
- {
- application_key_handler(theEvent.message & charCodeMask);
- }
- application_main();
- }
- }
-
- void HW_quit_event_loop(void)
- {
- done = true;
- }
-